/**
 * @Author: Lenovo
 * @Date: 2024/7/18 17:17
 * @description:
 */
public class MyQueue {
    static class ListNode{
        public int val;
        public ListNode prev;
        public ListNode next;

        public ListNode(int val) {
            this.val = val;
        }
    }
    public ListNode first;
    public ListNode last;
    public int usedSize = 0;
    public void offer(int data){
        ListNode node = new ListNode(data);
        if (isEmpty()){
            first = last = node;
        }else {
            last.next = node;
            node.prev = last;
            last = node;
        }
        this.usedSize++;
    }
    public int poll(){
        if (isEmpty()){
            return -1;
        }
        int val = first.val;
        first = first.next;
        if (first!=null){
            first.prev = null;
        }
        this.usedSize--;
        return val;
    }
    public int peek(){
        if (isEmpty()){
            return -1;
        }
        return first.val;
    }
    public boolean isEmpty(){
        return usedSize == 0;
    }
}
